package com.bw.service.impl;


import com.alibaba.fastjson.JSON;
import com.bw.entity.Book;
import com.bw.mapper.BookMapper;
import com.bw.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.swing.*;
import java.util.Arrays;
import java.util.List;

@Service
public class BookServiceImpl implements BookService {

    @Autowired
    BookMapper bookMapper;

    /**
     * 原生的写法 打印入参和返参
     * @param book
     * @return
     */
    @Override
    public Integer addBook(Book book) {
        System.out.println("BookServiceImpl addBook 入参是 " + JSON.toJSONString(book));
        //
        Integer integer = bookMapper.addBook(book);
        System.out.println("BookServiceImpl addBook 返参是 " + integer);
        return integer;

    }

    @Override
    public List<Book> selectBook(Book book) {

        System.out.println("BookServiceImpl  selectBook 正在执行");

        return Arrays.asList(Book.builder().id(1).name("哈利波特").build());
    }

    @Override
    public Integer updateBook(Book book) throws InterruptedException {
        System.out.println("BookServiceImpl  updateBook 正在执行");
        Thread.sleep(3*1000);
        return 100;
    }

    @Override
    public Integer delBook(Book book) {
        System.out.println("BookServiceImpl  delBook 正在执行");
        return 1;
    }
}
